package com.miaosha.ms_03.dao;

import com.miaosha.ms_03.domain.Goods;
import com.miaosha.ms_03.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GoodsDao {

    @Select("SELECT G.*,MG.miaosha_price, MG.STOCK_COUNT,MG.START_DATE,MG.END_DATE FROM goods G LEFT JOIN miaosha_goods MG ON G.ID = MG.GOODS_ID")
    List<GoodsVo> listGoodsVoList();

    @Select("SELECT G.*,MG.miaosha_price,MG.STOCK_COUNT,MG.START_DATE,MG.END_DATE FROM goods G LEFT JOIN miaosha_goods MG ON G.ID = MG.GOODS_ID WHERE G.ID = #{goodsId}")
    GoodsVo getGoodsById(@Param("goodsId") Long goodsId);

    @Update("UPDATE goods G SET G.GOODS_STOCK = ${goodsStock} WHERE G.ID = ${id}")
    Integer updateStock(Goods goods);
}
